"# -- coding: utf-8 --"
import random
class Role(object):
    role_list = []
    end = False
    def __init__(self,name,sex,equipment=None,blood=100):
        self.name = name
        self.sex = sex
        self.equipment = equipment
        self.blood = blood
        self.room = None

    @classmethod
    def register(cls):
        role_name = input('请输入姓名:')
        sex = input('请选择性别:')
        equipment = input('请选择是否装备防弹衣(True/False):')
        return role_name,sex,equipment

    def join_room(self,room):
        if room.person == 2:
            print('房间人数已满')
        else:
            room.person += 1
            self.room = room
            print(f"{self.name}加入房间{room.name}")

    def fight(self,role):
        if self.room == role.room and self.room :
            if role.equipment :
                role.blood -= 5
                print(f"{role.name}:{role.blood}")
            else:
                role.blood -= 10
                print(f"{role.name}:{role.blood}")
            if role.blood <= 0:
                global end
                end = True
                print(f'游戏结束,{role.name}已经阵亡')

class Room(object):
    room__list = []
    def __init__(self,name):
        self.person = 0
        self.name = name
        self.role_list = []
    @classmethod
    def room_build(cls,room_name):
        room = Room(room_name)
        cls.room__list.append(room)
        return room
    @classmethod
    def show_room(cls):
        for i in range(len(cls.room__list)):
            print(cls.room__list[i].name)

def menu():
    round = 0
    print('------------menu------------')
    while True:
        switch = input('请选择:1.创建角色 2.创建房间 3.查看房间 4.进入房间 5.战斗\n ')
        if switch == '1':
            role = Role(*Role.register())
            Role.role_list.append(role)
        if switch == '2':
            room_name = input('请输入房间名:')
            room = Room.room_build(room_name)
        if switch == '3':
            Room.show_room()
        if switch == '4':
            choice = int(input('请选择加入的房间序号:'))
            role.join_room(Room.room__list[choice-1])
        if switch == '5':
            while True:
                round += 1
                #每个回合随机用户发起攻击
                attack_order = random.sample((Role.role_list),2)
                print(f"round{round}\t{attack_order[0].name}先攻击\n")
                attack_order[0].fight(attack_order[1])
                if end:
                    break
                attack_order[1].fight(attack_order[0])
                if end:
                    break
end = False
menu()
